package com.smart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smart.model.domain.ProjectWeeklyTaskDO;
import com.smart.model.request.ProjectWeeklyTaskRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @author zhanghong
 */
@Repository
public interface ProjectWeeklyTaskMapper extends BaseMapper<ProjectWeeklyTaskDO> {
    ProjectWeeklyTaskDO selectDOById(Long id);
    List<ProjectWeeklyTaskDO> selectDOList(ProjectWeeklyTaskDO projectWeeklyTask);
    int insertDO(ProjectWeeklyTaskDO projectWeeklyTask);
    int batchInsertDO(List<ProjectWeeklyTaskDO> projectWeeklyTaskDOList);
    int updateDO(ProjectWeeklyTaskDO projectWeeklyTask);
    int deleteDOById(Long id);
    int deleteDOByIds(String[] ids);

    @Select({"<script>",
            "   select count(1) from project_weekly_task",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") ProjectWeeklyTaskRequest param);
    @Select({"<script>",
            "   select * from project_weekly_task",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<ProjectWeeklyTaskDO> pageQuery(@Param("param") ProjectWeeklyTaskRequest param, @Param("limit") int limit, @Param("offset") long offset);

    @Select("select * from project_weekly_task where year=#{year} and week_num=#{week} limit 1")
    ProjectWeeklyTaskDO queryByYearAndWeek(@Param("year") Integer year, @Param("week") Integer week);

    @Select("select * from project_weekly_task where start_time=#{startDate} and end_time=#{endDate} limit 1")
    ProjectWeeklyTaskDO getByStartAndEndTime(@Param("startDate") Date startDate, @Param("endDate") Date endDate);
}
